import { ApiProperty } from '@nestjs/swagger';
import {
  Column,
  Entity,
  JoinColumn,
  ManyToOne,
  PrimaryGeneratedColumn,
} from 'typeorm';
import { Order } from './order.entity';

export type PaymentMethodType = '线下到店支付' | '微信支付' | '支付宝支付';

@Entity()
export class Payment {
  @ApiProperty({ description: '支付记录ID', example: 1 })
  @PrimaryGeneratedColumn()
  paymentID: number;

  @ApiProperty({ description: '订单ID', example: 1 })
  @Column()
  orderID: number;

  @ApiProperty({
    description: '支付金额',
    example: 1500,
    minimum: 0,
  })
  @Column('float')
  amount: number;

  @ApiProperty({
    description: '支付方式',
    enum: ['线下到店支付', '微信支付', '支付宝支付'],
    default: '线下到店支付',
    example: '线下到店支付',
  })
  @Column({ default: '线下到店支付' })
  paymentMethod: PaymentMethodType;

  @ApiProperty({
    description: '是否已支付',
    default: false,
    example: false,
  })
  @Column({ default: false })
  isPaid: boolean;

  @ApiProperty({ description: '关联的订单', type: () => Order })
  @ManyToOne(() => Order, (order) => order.payments)
  @JoinColumn({ name: 'orderID' })
  order: Order;
}
